local skel = fk.CreateSkill {
  name = "emo__feidan",
  tags = {Skill.Limited},
}

Fk:loadTranslationTable{
  ["emo__feidan"] = "巡飞弹",
  [":emo__feidan"] = "昂扬技，结束阶段，你可以视为对一名角色使用多亮出X张牌，无视防具的【兵临城下】（X为其装备区牌数）。"..
  "<br>激昂：你造成致命伤害时，摸两张牌。",

  ["#emo__feidan-choose"] = "巡飞弹:你可以视为对1名角色使用无视防具的【兵临城下】",

  ["$emo__feidan1"] = "巡飞弹就绪",
  ["$emo__feidan2"] = "可以启动巡飞弹了",
}

skel:addEffect(fk.EventPhaseStart, {
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and player.phase == Player.Finish
    and player:usedSkillTimes(skel.name, Player.HistoryGame) == 0
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local card = Fk:cloneCard("mobile__enemy_at_the_gates")
    card.skillName = skel.name
    local targets = table.filter(room.alive_players, function (p)
      return player:canUseTo(card, p)
    end)
    local tos = room:askToChoosePlayers(player, {
      min_num = 1, max_num = 1, targets = targets, skill_name = skel.name,
      prompt = "#emo__feidan-choose",
    })
    if #tos > 0 then
      event:setCostData(self, {tos = tos})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    local card = Fk:cloneCard("enemy_at_the_gates")
    card.skillName = skel.name
    local x = #to:getCardIds("e")
    room:useCard{
      from = player, tos = {to}, card = card, extra_data = {num = x}
    }
  end,
})

skel:addEffect(fk.TargetSpecified, {
  can_refresh = function(self, event, target, player, data)
    if target == player and data.card.trueName == "slash" then
      local parent = player.room.logic:getCurrentEvent():findParent(GameEvent.CardEffect)
      if parent then
        local effect = parent.data
        return table.contains(effect.card.skillNames, skel.name)
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    data.to:addQinggangTag(data)
  end,
})

skel:addEffect(fk.DamageCaused, {
  is_delay_effect = true,
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and player:usedSkillTimes(skel.name, Player.HistoryGame) > 0
    and data.damage > 0 and (data.to.hp + data.to.shield) <= data.damage
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    player:drawCards(2, skel.name)
    player:setSkillUseHistory(skel.name, 0, Player.HistoryGame)
  end,
})


return skel
